<template>
	<view class="body">
		<up-tabs lineColor='#3f59a7' :list="data.menu" :current='data.type - 1' @click="setType"
			:scrollable='false'></up-tabs>
		<view class="list p20" v-if='data.list.length > 0'>
			<view class="item p20 mb20" v-for="(item, index) in data.list" :key="index">
				<view class="d-b-c">
					<view class="d-s-c flex-1">
						<view class="mr20" v-if="item.avatar">
							<up-avatar size="150rpx" :src="item.avatar"></up-avatar>
						</view>
						<view class="flex-1">
							<view class="fb f34 mr20">{{ item.userName || item.nickname }}</view>
							<view class="f28 mt10" v-if="item.mobile">{{ item.mobile }}</view>
							<view class="sub mt10 f28 mt20" v-if="item.credit1">积分：{{ item.credit1 }}</view>
						</view>
					</view>
					<view class="tag">
						<up-tag size="mini" v-if="item.parentName" plain color='#3f59a7' borderColor="#3f59a7"
							:text="item.parentName"></up-tag>
					</view>
				</view>
				<block v-if="data.type != 3">
					<view class="sub mt10 f28">入库数量：{{ item.in }}</view>
					<view class="sub mt10 f28">出库数量：{{ item.out }}</view>
					<view class="sub mt10 f28">退货数量：{{ item.return }}</view>
				</block>
			</view>
			<!-- <up-loadmore :status="data.status" line marginTop="20"></up-loadmore> -->
		</view>
		<up-empty v-else mode="list" text="暂无列表" marginTop="20vh"></up-empty>
	</view>
</template>
<script setup>
import { reactive } from 'vue'
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { useStore } from "vuex"
const store = useStore()
const data = reactive({
	menu: [],
	list: [],
	type: 0, //1经销商 2门店 3积分
	page: 1, //页数
	status: "loadmore",
	count: 1,
	_url: '',
	userID: '',
	identity: '',
})

function setType(e) {
	data.type = e.index + 1
	data.list = []
	data.page = 1
	getList()
}
async function getList() {
	if (data.list.length >= data.count) return
	if(data.identity=='管理员'){
		data._url = data.type == 3 ? store.state.api.statistics.score : store.state.api.statistics.userOrder;
	}else if(data.identity=='门店'){
		data._url =  store.state.api.statistics.userOneOrder;
	}else if(data.identity=='代理'){
		data._url = data.type == 1 ? store.state.api.statistics.userOneOrder : store.state.api.statistics.userOrder;
	}
	const res = await store.dispatch('request', {
		url: data._url,
		data: {
			userType: data.type, //1.代理 2.门店
			page: data.page, //分页参数 默认值:1
			userID: data.userID, //经销商ID
		}
	})
	if (res.code == 1) {
		data.count = res.data.count || res.data.total
		data.list = data.list.concat(res.data.data)
		data.page++
	}
	if (data.list.length >= res.data.count) data.status = 'nomore'
}
onLoad((options) => {
	data.user = uni.getStorageSync('userinfo')
	if (!data.user.oubi) {
		data.menu = [{
			name: "经销商"
		}, {
			name: "门店"
		}, {
			name: "积分"
		}]
		data.identity='管理员';
		
	} else {
		data.userID = data.user.oubi.userID
		if (data.user.oubi.userTypeName == '代理') {
			data.menu = [{
				name: "经销商"
			}, {
				name: "门店"
			}]
			data.identity='代理';
		} else {
			data.menu = [{
				name: "门店"
			}]
			data.identity='门店';
		}
	}
	data.type = options.type
	getList()
})
onReachBottom(() => {
	getList()
})
</script>
<style scoped lang="scss">
.body {
	background-color: #f6f6f6;
}

.item {
	background-color: #fff;
	border-radius: 10rpx;
}

.tag {
	max-width: 200rpx;
}
</style>